import { request } from '@umijs/max';
import { IRes, IResPage } from '.';
import { EApplication, IAuth } from './account';
import { IPermission } from './permission';

export interface IUserInfo {
  address: string;
  birthday: string;
  cellphone: string;
  departmentCode: string;
  effectiveDate: string;
  email: string;
  englishName: string;
  gender: string;
  id: number;
  idCardNo: string;
  idCardType: string;
  invalidDate: string;
  loginStatus: string;
  nickName: string;
  orgCode: string;
  parentCode: string;
  password: string;
  path: string;
  portrait: string;
  positionCode: string;
  qq: string;
  realName: string;
  remark: string;
  status: string;
  userCode: string;
  userType: string;
  username: string;
  wxUnionId: string;
  createTime: string;
  roleCodes: string[];
  roleNames: string[];
}

export async function apiAuthUserinfo(id: IAuth['loginId']) {
  return request<IRes<IUserInfo>>('/v1/zl/auth/userinfo/' + id, {
    method: 'GET',
  });
}

export async function apiAuthLoginInfo(params: { loginId: IAuth['loginId'] }) {
  return request<
    IRes<{ authorityResultVo: IUserInfo; permissionVoList: IPermission[] }>
  >('/v1/auth/account/getLoginInfoById', {
    method: 'GET',
    params: { ...params, userType: EApplication.application },
  });
}

export async function apiAuthUserinfoPage(params: Partial<IUserInfo>) {
  return request<IResPage<IUserInfo>>('/v1/auth/userinfo/page', {
    method: 'GET',
    params,
  });
}

export async function apiAuthUserinfoSave(data: Partial<IUserInfo>) {
  return request<IResPage<IUserInfo>>('/v1/auth/userinfo/save', {
    method: 'POST',
    data,
  });
}

export async function apiAuthUserinfoUpdate(data: Partial<IUserInfo>) {
  return request<IResPage<IUserInfo>>('/v1/auth/userinfo/update', {
    method: 'PUT',
    data,
  });
}

export async function apiAuthUserinfoBatchDelete(params: {
  ids: IUserInfo['id'][];
}) {
  return request<IRes<boolean>>(`/v1/auth/userinfo/${params.ids}`, {
    method: 'DELETE',
  });
}

export async function apiAuthUserinfoUpdatePWD(data: {
  id: IUserInfo['id'];
  newPwd: string;
  pwd: string;
}) {
  return request<IRes<boolean>>('/v1/auth/userinfo/resetPWD', {
    method: 'PUT',
    data,
  });
}
